<template>
  <div>
    <div class="firstdemo">
      <el-form ref="form" :model="form" label-width="100px">
        <el-row type="flex" justify="center">
          <el-col :span="5">
            <el-form-item label-width="70px">
              <span><font color="pink" size="3">注册页面</font></span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="5">
            <el-form-item label="账户：" prop="name">
              <el-input v-model="form.username" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="5">
            <el-form-item label="密码：" prop="password">
              <el-input v-model="form.password" size="small"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" justify="center">
          <el-col :span="5">
            <el-form-item>
              <el-button type="primary" @click="submit">注册</el-button>
              <el-button @click="register">切换到登陆</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

    </div>
  </div>
</template>

<script>
export default {
name: "register",
  data () {
    return {
      form:{
        username:'',
        password:'',
      },

    }
  },
  methods:{
    /*提交进行判断的函数 */
    async submit(){
      const res = await this.$http.post('user/register/',this.form)
      console.log(res.data)
      console.log(res)
      if(res.data.status==200){
        this.$message.success("注册成功")
        // window.localStorage.setItem("token",res.data.token)
        // this.$router.push('/lunbo')
      }else {
        this.$message.error("该用户已经被注册")
      }
    },
    register:function(){
      this.$router.push('/login')
    },
  },
}
</script>

<style scoped>

</style>
